<?php

namespace app\service\token;

use think\Cache;
/**
 * @property-read string[] $payload
 * @property-read string[] $header
 */
class Token
{

    protected $store;
    public $header;
    public $payload;
    function __construct($header,$payload,$store)
    {
        $this->store =  $store;        
        $this->header = $header;
        $this->payload = $payload;
    }

    function __get($name)
    {
        if(in_array($name,['header','payload'])){
            return $this->$name;
        }
        return null;
    }

    function __toString()
    {
        return $this->store->encodeToken($this->header,$this->payload);
    }
}